This is an abandoned effort to gets populations of Travis (or some geo) by zip code that could be used later with MixBev lesson.
HUD ZIP crosswalk file.
library(tidyverse)
library(tidycensus)
library(DT)
library(readxl)
library(janitor)
library(scales)
zips_raw <- read_excel(
"data-raw/ZIP_COUNTY_092021.xlsx",
) %>% clean_names()
zips <- zips_raw %>%
mutate(
res_ratio = round(res_ratio, 3),
bus_ratio = round(bus_ratio, 3),
oth_ratio = round(oth_ratio, 3),
tot_ratio = round(tot_ratio, 3),
)
zips %>% glimpse()
Rows: 54,262
Columns: 8
$ zip <chr> "00501", "00601", "00601", "00602", "00602", "…
$ county <chr> "36103", "72113", "72001", "72003", "72005", "…
$ usps_zip_pref_city <chr> "HOLTSVILLE", "ADJUNTAS", "ADJUNTAS", "AGUADA"…
$ usps_zip_pref_state <chr> "NY", "PR", "PR", "PR", "PR", "PR", "PR", "PR"…
$ res_ratio <dbl> 0.000, 0.160, 0.840, 1.000, 0.000, 0.000, 0.99…
$ bus_ratio <dbl> 1.000, 0.199, 0.801, 0.999, 0.001, 0.000, 0.99…
$ oth_ratio <dbl> 0.000, 0.129, 0.871, 1.000, 0.000, 0.000, 1.00…
$ tot_ratio <dbl> 1.000, 0.162, 0.838, 1.000, 0.000, 0.000, 0.99…
List of FIPS
fips_msa <- c("48021", "48055", "48209", "48453", "48491")
fips_travis <- c("48453")
fips_htw <- c("48209", "48453", "48491")
zips_filtered <- zips %>%
filter(
county %in% fips_travis,
bus_ratio > 0.33
) %>%
arrange(tot_ratio)
zips_filtered
zips_selected <- zips_filtered %>%
select(zip) %>% .$zip
Total pop: B01001_001
v19 <- load_variables(2019, "acs5/subject", cache = TRUE)
v19 %>% datatable()
Warning in instance$preRenderHook(instance) :
It seems your data is too big for client-side DataTables. You may consider server-side processing: https://rstudio.github.io/DT/server.html
Warning in instance$preRenderHook(instance) :
It seems your data is too big for client-side DataTables. You may consider server-side processing: https://rstudio.github.io/DT/server.html
pop_zip <- get_acs(
year = 2019,
variables = "S0101_C01_001",
geography = "zcta",
state = "TX",
# geometry = T,
) %>% clean_names()
Getting data from the 2015-2019 5-year ACS
Using the ACS Subject Tables
Using FIPS code '48' for state 'TX'
pop_zip_geo <- get_acs(
year = 2019,
variables = "S0101_C01_001",
geography = "zcta",
state = "TX",
geometry = T,
) %>% clean_names()
Getting data from the 2015-2019 5-year ACS
Downloading feature geometry from the Census website. To cache shapefiles for use in future sessions, set `options(tigris_use_cache = TRUE)`.
Using the ACS Subject Tables
Using FIPS code '48' for state 'TX'
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 3%
|
|== | 4%
|
|=== | 4%
|
|=== | 5%
|
|==== | 6%
|
|==== | 7%
|
|===== | 7%
|
|===== | 8%
|
|====== | 9%
|
|====== | 10%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|======== | 13%
|
|========= | 13%
|
|========= | 14%
|
|========== | 14%
|
|========== | 15%
|
|=========== | 17%
|
|============ | 18%
|
|============ | 19%
|
|============= | 19%
|
|============= | 20%
|
|============== | 21%
|
|=============== | 22%
|
|=============== | 23%
|
|================ | 24%
|
|================ | 25%
|
|================= | 25%
|
|================== | 27%
|
|=================== | 28%
|
|=================== | 29%
|
|==================== | 30%
|
|==================== | 31%
|
|===================== | 32%
|
|====================== | 34%
|
|======================= | 34%
|
|======================= | 35%
|
|======================== | 36%
|
|======================== | 37%
|
|========================= | 37%
|
|========================= | 38%
|
|========================= | 39%
|
|========================== | 39%
|
|========================== | 40%
|
|=========================== | 40%
|
|=========================== | 41%
|
|=========================== | 42%
|
|============================ | 42%
|
|============================ | 43%
|
|============================= | 43%
|
|============================= | 44%
|
|============================= | 45%
|
|============================== | 45%
|
|============================== | 46%
|
|=============================== | 46%
|
|=============================== | 47%
|
|================================ | 49%
|
|================================= | 49%
|
|================================= | 50%
|
|================================= | 51%
|
|================================== | 51%
|
|=================================== | 53%
|
|=================================== | 54%
|
|==================================== | 54%
|
|==================================== | 55%
|
|===================================== | 57%
|
|======================================= | 58%
|
|======================================= | 59%
|
|======================================== | 60%
|
|======================================== | 61%
|
|========================================= | 61%
|
|========================================= | 63%
|
|========================================== | 64%
|
|=========================================== | 64%
|
|=========================================== | 65%
|
|=========================================== | 66%
|
|============================================ | 67%
|
|============================================= | 67%
|
|============================================= | 68%
|
|============================================= | 69%
|
|============================================== | 69%
|
|============================================== | 70%
|
|=============================================== | 71%
|
|=============================================== | 72%
|
|================================================ | 72%
|
|================================================ | 73%
|
|================================================= | 75%
|
|================================================== | 75%
|
|================================================== | 76%
|
|=================================================== | 77%
|
|=================================================== | 78%
|
|==================================================== | 78%
|
|==================================================== | 79%
|
|===================================================== | 80%
|
|===================================================== | 81%
|
|====================================================== | 81%
|
|====================================================== | 82%
|
|======================================================= | 84%
|
|======================================================== | 84%
|
|======================================================== | 85%
|
|========================================================= | 86%
|
|========================================================= | 87%
|
|========================================================== | 88%
|
|=========================================================== | 89%
|
|=========================================================== | 90%
|
|============================================================ | 90%
|
|============================================================ | 91%
|
|============================================================ | 92%
|
|============================================================= | 93%
|
|============================================================== | 94%
|
|============================================================== | 95%
|
|=============================================================== | 95%
|
|================================================================ | 97%
|
|================================================================ | 98%
|
|================================================================= | 98%
|
|==================================================================| 100%
pop_zip
pop_zip_filtered <- pop_zip_geo %>%
filter(geoid %in% zips_selected)
pop_zip_filtered %>%
arrange(estimate %>% desc())
Simple feature collection with 47 features and 5 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -98.2715 ymin: 30.06706 xmax: -97.42322 ymax: 30.5396
Geodetic CRS: NAD83
First 10 features:
geoid name variable estimate moe
1 78660 ZCTA5 78660 S0101_C01_001 91300 2426
2 78745 ZCTA5 78745 S0101_C01_001 61907 1672
3 78753 ZCTA5 78753 S0101_C01_001 60426 1990
4 78741 ZCTA5 78741 S0101_C01_001 52114 1583
5 78748 ZCTA5 78748 S0101_C01_001 51653 1935
6 78744 ZCTA5 78744 S0101_C01_001 50123 1867
7 78758 ZCTA5 78758 S0101_C01_001 48993 1753
8 78704 ZCTA5 78704 S0101_C01_001 48746 1624
9 78759 ZCTA5 78759 S0101_C01_001 43298 1262
10 78749 ZCTA5 78749 S0101_C01_001 38041 1522
geometry
1 MULTIPOLYGON (((-97.67159 3...
2 MULTIPOLYGON (((-97.84494 3...
3 MULTIPOLYGON (((-97.71049 3...
4 MULTIPOLYGON (((-97.74935 3...
5 MULTIPOLYGON (((-97.86015 3...
6 MULTIPOLYGON (((-97.7886 30...
7 MULTIPOLYGON (((-97.74113 3...
8 MULTIPOLYGON (((-97.80094 3...
9 MULTIPOLYGON (((-97.81081 3...
10 MULTIPOLYGON (((-97.89444 3...
pop_zip_filtered %>%
ggplot() +
geom_sf(aes(fill = estimate)) +
theme_void() +
theme(plot.margin = unit(c(10,10,10,10), "pt")) +
scale_fill_distiller(
# palette = "Greens",
direction = 1,
name = "Population",
label = comma
)